<?php
require_once BASE_PATH.'/db/database.php';

class Sys extends Database{

    public function SysConfig() {

        $sql = "SELECT * FROM `setting` order by id";
        $res = json_decode($this->getAll($sql),true);

        foreach ($res as $item) {
            $result[$item['set_key']] = $item['set_values'];
        }

        return json_encode($result);
    }

    public function updateSetting($data) {
        $web_desc = $data['web_desc'];
        $web_keywords = $data['web_keywords'];
        $create_time = strtotime($data['create_time']);
        $contact = $data['contact'];
        $ai_check = $data['ai_check'];

        $web_desc = htmlspecialchars(daddslashes($web_desc));
        $web_keywords = htmlspecialchars(daddslashes($web_keywords));
        $contact = htmlspecialchars(daddslashes($contact));


        $sql = "UPDATE setting SET 
                    set_values = CASE 
                        WHEN set_key = 'web_desc' THEN '$web_desc' 
                        WHEN set_key = 'web_keywords' THEN '$web_keywords' 
                        WHEN set_key = 'create_time' THEN '$create_time' 
                        WHEN set_key = 'contact' THEN '$contact' 
                        WHEN set_key = 'ai_check' THEN '$ai_check' 
                    END 
                WHERE set_key IN ('web_desc', 'web_keywords', 'create_time', 'contact', 'ai_check')";

        $this->query($sql);
    }

}
?>
